<!DOCTYPE html>
<html>
<head>
	<title>Menu Automated (non-robot) Tests</title>

	<script type="text/javascript" src="boilerplate.js"></script>

	<script type="text/javascript">
		require([
			"doh/runner",
			"dojo/dom", "dojo/dom-class", "dojo/on", "dojo/parser", "dojo/query",
			"dijit/registry", "dijit/RadioMenuItem",
			"dojo/NodeList-dom",	// allows NodeList.attr()
			"dijit/DropDownMenu", "dijit/MenuSeparator",			// used only by parser
			"dojo/domReady!"
		], function(doh, dom, domClass, on, parser, query, registry, RadioMenuItem){

			doh.register("parse", function parse(){
				return parser.parse();
			});

			doh.register("RadioMenuItem", [
				function click(){
					// initial conditions
					doh.is("g1r2, g2r2", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "initially checked");

					// click to change selected value in group 1; group 2 shouldn't change
					on.emit(dom.byId("g1r3"), "click", {bubbles: true, cancelable: true});
					doh.is("g1r3, g2r2", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "clicked g1r3");

					// click to change selected value in group 2; group 1 shouldn't change
					on.emit(dom.byId("g2r1"), "click", {bubbles: true, cancelable: true});
					doh.is("g1r3, g2r1", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "clicked g2r1");

					// click currently selected node; shouldn't change anything
					on.emit(dom.byId("g1r3"), "click", {bubbles: true, cancelable: true});
					doh.is("g1r3, g2r1", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "clicked g1r3 again");
				},
				function set(){
					// change selected item in group 1
					g1r1.set("checked", true);
					doh.is("g1r1, g2r1", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "set g2r1");

					// clear selected item in group 1
					g1r1.set("checked", false);
					doh.is("g2r1", query(".dijitRadioMenuItemChecked").attr("id").join(", "), "cleared g2r1");
				},
				function destroySelected(){
					// Test to make sure that destroying the selected node and recreating it doesn't throw an exception
					g1r1.set("checked", true);
					g1r1.destroyRecursive();
					var reincarnated = new RadioMenuItem({
						id: "g1r1",
						group: "g1",
						checked: true,
						label: "reincarnated"
					});
					registry.byId("menu").addChild(reincarnated, 2);
				}
			]);

			doh.run();
		});
	</script>
</head>
<body class="claro">
	<h1 class="testTitle">Menu Automated (non-robot) tests</h1>
	<div id="menu" data-dojo-type="dijit/DropDownMenu">
		<div id="g1r1" data-dojo-id="g1r1" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g1'">red</div>
		<div id="g1r2" data-dojo-id="g1r2" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g1', checked:true">yellow</div>
		<div id="g1r3" data-dojo-id="g1r3" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g1', checked:false /*set to false for testing*/">green</div>
		<div data-dojo-type="dijit/MenuSeparator"></div>
		<div id="g2r1" data-dojo-id="g2r1" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g2'">small</div>
		<div id="g2r2" data-dojo-id="g2r2" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g2', checked:true">normal</div>
		<div id="g2r3" data-dojo-id="g2r3" data-dojo-type="dijit/RadioMenuItem"
			 data-dojo-props="group: 'g2'">large</div>
	</div>
</body>
</html>
